<style lang="less">
  @import '../../styles/common.less';
</style>


<template>
  <div>
    <Button type="primary" size="large" @click="add">添加课程</Button>
    <Table border :columns="columns" :data="data" style="margin-top: 20px;"></Table>
  </div>
</template>

<script>
    import moment from 'moment'
    export default {
        name: "stduent-info",
        data(){
          return{
            columns: [
              {
                title: '编号',
                key: 'id'
              },
              {
                title: '活动名称',
                key: 'activityName'
              },
              {
                title: '活动类型',
                key: 'activityType'
              },
              {
                title: '提交时间',
                key: 'createTime',
                render:function (h,params) {
                  console.log(params);
                  return h('div',
                    moment(params.row.createTime).format('YYYY-MM-DD HH:mm:ss'));
                }
              },
              {
                title: '操作',
                key: 'action',
                width: 180,
                align: 'center',
                render: (h, params) => {
                  return h('div', [
                    h('Button', {
                      props: {
                        type: 'primary',
                        size: 'small'
                      },
                      style: {
                        marginRight: '5px'
                      },
                      on: {
                        click: () => {
                          this.show(params.index)
                        }
                      }
                    }, '查看'),
                    h('Button', {
                      props: {
                        type: 'primary',
                        size: 'small'
                      },
                      style: {
                        marginRight: '5px'
                      },
                      on: {
                        click: () => {
                          this.edit(params.index)
                        }
                      }
                    }, '修改'),
                    h('Button', {
                      props: {
                        type: 'error',
                        size: 'small'
                      },
                      on: {
                        click: () => {
                          this.remove(params.index)
                        }
                      }
                    }, '删除')
                  ]);
                }
              }
            ],
            data: [

            ]
          }
        },
        methods:{
          add(){
            this.$router.push({
              name: 'activity_mod'
            });
          },
          edit(index){
            this.$router.push({
              name: 'activity_mod',
              query:{id:this.data[index].id}
            });
          },
          show (index) {
            this.$Modal.confirm({
              title: '课程信息',
              content: `活动名称：${this.data[index].activityName}<br>
                        活动分类：${this.data[index].activityType}<br>
                        活动属性：${this.data[index].activityAttr}<br>
                        活动地点：${this.data[index].activityAddress}<br>
                        活动时间：${moment(this.data[index].activityTime).format('YYYY-MM-DD HH:mm:ss')}<br>
                        活动人数：${this.data[index].activityPersons}<br>
                        活动状态：${this.data[index].activityState}<br>
                        提交时间：${moment(this.data[index].createTime).format('YYYY-MM-DD HH:mm:ss')}<br>
                        `,
            })
          },
          remove (index) {
            this.$http.get('/school/delActivity?id='+this.data[index].id).then(res => {
              console.log(res);
              this.$Message.success("删除成功")
              this.data.splice(index, 1);
            })
          }
        },
        mounted(){
          this.$http.get('/school/getActivitys').then(res => {
            this.data = res.data.data;
          });
        }
    }
</script>

<style scoped>

</style>
